package com.qs.eggs.api;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.StringCallback;
import com.qs.eggs.Constants;

import java.util.HashMap;

/**
 * Created by Administrator on 2017/5/3.
 */

public class HttpApi {

    /**
     * 验证手机号是否注册
     */

    public static void cheakPhone(String phone,StringCallback callback){
        HashMap<String,String> map=new HashMap<>();
        map.put("phone",phone);
        Gson gson=new Gson();
        String parmas=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"register?action=isExitsPhone")
                .params("data",parmas)
                .execute(callback);
    }
    /**
     * 提交注册
     */

    public static void upRegister(HashMap<String,String> map,StringCallback callback){
        Gson gson=new Gson();
        String parmas=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"register?action=addCoustomer")
                .params("data",parmas)
                .execute(callback);
    }

    /**
     * 判断是否登录
     */

    public static void cheakIsLogin(StringCallback callback){
        OkGo.post(Constants.URL_BASE+"mallLogin?action=isLogin")
                .execute(callback);
    }
    /**
     * 获取手机验证码
     */
    public static void sendSmsCode(String phone,StringCallback callback){

        HashMap<String,String> map=new HashMap<>();
        map.put("phone",phone);
        Gson gson=new Gson();
        String params=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"register?action=getSMSCode")
                .params("params",params)
                .execute(callback);
    }
    /**
     * 分类页接口
     * 加载产品分类(第一级列表)
     * @param callback
     */
    public static void FirstCategoryList(StringCallback callback){

        OkGo.post(Constants.URL_BASE+"mall/showproduct?action=getProductTress")
                .execute(callback);
    }
    /**
     * 分类页接口
     * 加载分类对应的产品(第二级列表)
     * @param callback
     */
    public static void SecondCategoryList(String proid,StringCallback callback){

        HashMap<String,String> map=new HashMap<>();
        map.put("protypeidother",proid);
        map.put("sorts","zonghe");
        Gson gson=new Gson();
        String params=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"mall/showproduct?action=loadProductInfo")
                .params("params",params)
                .execute(callback);
    }

    /**
     * 更多产品
     */
    public static void morePro(String biaoshi,String sorts,StringCallback callback){

        HashMap<String,String> map=new HashMap<>();
        map.put("biaoshi",biaoshi);
        map.put("sorts",sorts);
        Gson gson=new Gson();
        String params=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"mall/showproduct?action=loadProductInfo")
                .params("params",params)
                .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
                .execute(callback);
    }

    /**
     * 搜索产品
     */
    public static void searchPro(String comment,String sorts,StringCallback callback){

        HashMap<String,String> map=new HashMap<>();
        map.put("pronameLIKE",comment);
        map.put("sorts",sorts);
        Gson gson=new Gson();
        String params=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"mall/showproduct?action=loadProductInfo")
                .params("params",params)
                .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
                .execute(callback);
    }
    /**
     * 搜索产品
     */
    public static void bennrtPro(String comment,String sorts,StringCallback callback){

        HashMap<String,String> map=new HashMap<>();
        map.put("specialid",comment);
        map.put("sorts",sorts);
        Gson gson=new Gson();
        String params=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"mall/showproduct?action=loadProductInfo")
                .params("params",params)
                .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
                .execute(callback);
    }
    /**
     * 加载省信息列表
     */
    public static void getProvince(StringCallback callback){
        OkGo.post(Constants.URL_BASE+"register?action=loadProvince")
                .execute(callback);
    }
    /**
     * 加载市信息列表
     */
    public static void getCity(String ProvinceId,StringCallback callback){
        HashMap<String,String> map=new HashMap<>();
        map.put("provinceid",ProvinceId);
        Gson gson=new Gson();
        String parmas=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"register?action=loadCity")
                .params("params",parmas)
                .execute(callback);
    }
    /**
     * 加载县信息列表
     */
    public static void getCounty(String cityid,StringCallback callback){
        HashMap<String,String> map=new HashMap<>();
        map.put("cityid",cityid);
        Gson gson=new Gson();
        String parmas=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"register?action=loadCountry")
                .params("params",parmas)
                .execute(callback);
    }
    /**
     * 加载小区信息列表
     */
    public static void getCommunity(String countryid,StringCallback callback){
        HashMap<String,String> map=new HashMap<>();
        map.put("countryid",countryid);
        Gson gson=new Gson();
        String parmas=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"register?action=loadXiaoqu")
                .params("params",parmas)
                .execute(callback);
    }

    /**
     * 加载商家信息列表
     */
    public static void getShangjia(String countryid,StringCallback callback){
        HashMap<String,String> map=new HashMap<>();
        map.put("areaid",countryid);
        Gson gson=new Gson();
        String parmas=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"changezoneServlet?action=loadBuiness")
                .params("params",parmas)
                .execute(callback);
    }

    /**
     * 加载商家详细信息
     */
    public static void getShangjiaDetail(String id,StringCallback callback){
        HashMap<String,String> map=new HashMap<>();
        map.put("id",id);
        Gson gson=new Gson();
        String parmas=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"changezoneServlet?action=loadBuinessDetail")
                .params("params",parmas)
                .execute(callback);
    }
    /**
     * 加载负责人信息列表
     */
    public static void getHeader(String xiaoquid,StringCallback callback){
        HashMap<String,String> map=new HashMap<>();
        map.put("xiaoquid",xiaoquid);
        Gson gson=new Gson();
        String parmas=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"register?action=loadChargeid")
                .params("params",parmas)
                .execute(callback);
    }

    /**
     * 加载商品评价列表
     */
    public static void getEvaluationList(String proid,String type,String flag,StringCallback callback){
        HashMap<String,String> map=new HashMap<>();
        map.put("proid",proid);
        map.put("type",type);
        //加载全部评论不传此字段
        if(!flag.equals("")){
            map.put("flag",flag);
        }

        Gson gson=new Gson();
        String parmas=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"evaulteManage?action=searchEvalute")
                .params("params",parmas)
                .execute(callback);
    }

    /**
     * 获取购物车商品
     */

    public static void getCartPro(StringCallback callback){
        OkGo.post(Constants.URL_BASE+"shoppingcart?action=searchShoppingCart")
                .execute(callback);
    }

    /**
     * 删除购物车商品
     */

    public static void delCartPro(String ids,StringCallback callback){
        HashMap<String,String> dataMap=new HashMap<>();
        dataMap.put("ids",ids);
        Gson gson=new Gson();
        String params=gson.toJson(dataMap);

        OkGo.post(Constants.URL_BASE+"shoppingcart?action=deleteShoppingCart")
                .params("data",params)
                .execute(callback);
    }

    /**
     * 获取个人订单列表
     */

    public static void getOrders(String orderstatus,StringCallback callback){

        HashMap<String,String> map=new HashMap<>();
        map.put("orderstatus",orderstatus);
        Gson gson=new Gson();
        String params=gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"myorder?action=searchMyOrder")
                .params("data",params)
                .execute(callback);
    }

}
